export function getPageParams(name : string){
    return new Promise<any>(resolve=>{ 
        if(name){
            const params = getParams(name)
            if(params){
                resolve(params)
            }
        }
        resolve( null )
    }) 
}

export function setPageParams( name: string,params: object){
    return new Promise(resolve =>{
        if(name){
            const data = getData(name)
            if(data){
                localStorage.setItem(name, JSON.stringify({params, data}))
            }else{
                localStorage.setItem(name, JSON.stringify({params}))
            }            
        } 
        resolve(0)
    })
}

export function getPageData(name : string){
    return new Promise<any>(resolve=>{ 
        if(name){
            const data = getData(name)
            if(data){
                resolve(data)
            }
        }
        resolve( null )
    }) 
}

export function setPageData( name: string, data: object){
    return new Promise(resolve =>{
        if(name){
            const params = getParams(name)
            if(params){
                localStorage.setItem(name, JSON.stringify({params, data}))
            }else{
                localStorage.setItem(name, JSON.stringify({data}))
            }            
        } 
        resolve(0)
    })
}


function getParams(name: string){
    const storageData = localStorage.getItem(name)
    if(storageData){
        const pageData = JSON.parse(storageData)
        return pageData.params 
    }
    return null
}

function getData(name: string){
    const storageData = localStorage.getItem(name)
    if(storageData){
        const pageData = JSON.parse(storageData)
        return pageData.data 
    }
    return null
}